package org.chen;

import org.chen.pool.JedisConnect;

public class DelayMsgQueueTest {
  public static void main(String[] args) {
    JedisConnect connect = new JedisConnect();
    connect.execute(jedis->{
      //创建消息队列-chen
      DelayMsgQueue delayMsgQueue = new DelayMsgQueue(jedis,"chen");

      //创建消息生产者
      Thread producer = new Thread(){
        @Override
        public void run() {
          for (int i = 0; i < 5; i++) {
            //发送消息
            delayMsgQueue.queue("hello redis!>>>>"+i);
          }
        }
      };

      //创建消息消费者
      Thread consumer = new Thread(){
        @Override
        public void run() {
          //接收消息
          delayMsgQueue.loop();
        }
      };

      //启动
      producer.start();
      consumer.start();

      //停止程序，不停止的话消费者会一直监听等待接收消息
      try {
        Thread.sleep(8000);
        consumer.interrupt();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    });
  }
}
